
let activity_tag = 'ysfsfq'
let request_key = 'help'

let userids = "cb895525e5435be500b840a5e50059854daa84@cb895525e84a50e303b341a4e10455874da98e@cb895525e84a51e201b94ea5eb0459854aac8c@cb895525e84a51e202b240ade4035f8c48af8e@cb895525e84a57e502b049a3e10d5e8349a98e@cb895525e84a51e203b24aace6045b8045aa8c@cb895525e84a51e202b34fa3e0045c8748a98a@cb895525e8485be104b640a4e600548d49ae8c@cb895525e84a51e600b74ea3e2055b8d45ae8c@cb895525e84a56e104b14aade3055c8644ad8a@cb895525e84f52e200b549a6e2055c8c48aa88"
let useridArray = userids.split("@")

function sfq($request) {
    console.log(`开始完成送福气任务`);
    // setTimeout(axios_skill,2000,useridArray[7],$request);
    for (let i = 0; i < 2; i++) {
        setTimeout(randomGift, (i + 1) * 10000, $request, i + 1);
    }
    for (let j = 0; j < useridArray.length; j++) {

        setTimeout(axios_skill, (j + 3) * 10000, useridArray[j], $request, j + 1);
    }

}

//上面是暂时需要适配的部分
!(async () => {
    if (typeof $request !== "undefined") {
        let body = $response.body;
        body = JSON.parse(body)
        body.data.redpackAmount = 888
        $done(JSON.stringify(body))
        sfq($request)
    }
})()
    .catch((e) => console.log(e))
    .finally(() => $done())

function axios_skill(userid, request_body, count) {
    console.log('第' + count + '次互助');
    var request_lib = require('request');
    var headers = {
        'Accept': 'application/json, text/plain, */*',
        'Authorization': request_body.headers.Authorization,
        'Accept-Language': 'zh-cn',
        'Content-Type': 'application/json',
        'Origin': 'https://youhui.95516.com',
        'User-Agent': request_body.headers['User-Agent'],
        'Connection': 'keep-alive',
        'Referer': 'https://youhui.95516.com/newsign/ysfsfq/index.html?userId=' + userid + '&greetingId=1&baifuId=1',
        'Cookie': request_body.headers.Cookie
    };
    var dataString = '{"token":"' + userid + '","baifuId":"1","greetingId":"1"}';
    if (count == 1) {
        console.log(headers);
        console.log(dataString);
    }
    var options = {
        url: 'https://youhui.95516.com/newsign/ysfsfq/api/fuqi/receive',
        method: 'POST',
        headers: headers,
        body: dataString
    };
    request_lib(options, callback);

}


function randomGift(request_body, count) {
    console.log('第' + count + '次击鼓');
    var request = require('request');

    var headers = {
        'Host': 'youhui.95516.com',
        'Origin': 'https://youhui.95516.com',
        'Accept-Encoding': 'gzip, deflate, br',
        'Connection': 'keep-alive',
        'Accept': 'application/json, text/plain, */*',
        'User-Agent': request_body.headers['User-Agent'],
        'Authorization': request_body.headers.Authorization,
        'Referer': 'https://youhui.95516.com/newsign/ysfsfq/index.html',
        'Accept-Language': 'zh-cn',
        'Cookie': request_body.headers.Cookie
    };

    var options = {
        url: 'https://youhui.95516.com/newsign/ysfsfq/api/fuqi/randomGift',
        method: 'POST',
        headers: headers
    };

    request(options, callback);
}

function callback(error, response, body) {
    console.log(body);
}

//生成从minNum到maxNum的随机数
function randomNum(minNum, maxNum) {
    switch (arguments.length) {
        case 1:
            return parseInt(Math.random() * minNum + 1, 10);
            break;
        case 2:
            return parseInt(Math.random() * (maxNum - minNum + 1) + minNum, 10);
            break;
        default:
            return 0;
            break;
    }
}